package com.tjs.lucky.application.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.tjs.lucky.common.Constants.*;

/**
 * @author tianjiashu（mac）
 * @ClassName QueueConfig.java
 * @Description 配置队列
 * @createTime 2023年06月20日 11:11:00
 */
@Configuration
public class QueueConfig {

    @Bean
    public DirectExchange luckyExchange() {
        return new DirectExchange(EXCHANGE_NAME);
    }

    /**
     * 处理发奖
     */
    @Bean
    public Queue disAwardQueue() {
        return QueueBuilder.durable(DIS_AWARD_QUEUE_NAME)
                .deadLetterExchange(DL_EXCHANGE_NAME)
                .deadLetterRoutingKey("dl")
                .build();
    }

    @Bean
    public Binding disAwardBinding(Queue disAwardQueue, DirectExchange luckyExchange) {
        return BindingBuilder.bind(disAwardQueue).to(luckyExchange).with("award");
    }

}
